# -*- coding: utf8 -*-
import requests
import time
import re
import json

def start():
    try:
        cookie = 'c7f3uiqfdUZDm3NHa2MiUqLR9PlVekW5rkT031qUbm1gIX7FEjezsrQiAl7kgPWIc6LZ35'

        headers = {'Cookie':cookie}

        login = requests.get('https://static.iqiyi.com/js/qiyiV2/20200212173428/common/common.js',headers=headers).text

        regex1 = re.compile("platform:\"(.*?)\"")
        platform = regex1.findall(login)
        url = 'https://tc.vip.iqiyi.com/taskCenter/task/userSign?P00001='+cookie+'&platform='+platform[0] + '&lang=zh_CN&app_lm=cn&deviceID=pcw-pc&version=v2'

        sign = requests.get(url,headers).text
        res = json.loads(sign)
        res = res["data"]["acquireGiftList"][0]
        print(res)

        if 'Account Verify Error' in res:
            print('cookies失效！')
            requests.get('https://sc.ftqq.com/SCU54227T9cef98d441454319935c5b76f8bd49545d136637ac860.send' + '?text= 爱奇艺自动签到失败_'+time.strftime('%Y.%m.%d',time.localtime(time.time())) +'&desp='+'cookies失效，请更新')
        else:
            print('签到完成！')
            requests.get('https://sc.ftqq.com/SCU54227T9cef98d441454319935c5b76f8bd49545d136637ac860.send' + '?text= 爱奇艺自动签到成功_'+time.strftime('%Y.%m.%d',time.localtime(time.time())) +'&desp='+ res)
    except Exception as e:
        print("地址访问失败！")
        requests.get('https://sc.ftqq.com/SCU54227T9cef98d441454319935c5b76f8bd49545d136637ac860.send' + '?text= 爱奇艺自动签到失败_'+time.strftime('%Y.%m.%d',time.localtime(time.time())) +'&desp='+'异常代码：\n'+str(e))

def main_handler(event, context):
    return start()
if __name__ == '__main__':
    start()